$(document).ready(function(){	
	$("#addUser").val(username);
	var src = tl_config.his_url;
	var i = src.indexOf('?');
	var jj =src.indexOf('&');
	if(i!=-1){		
		var cateId = src.substring(i+8,jj);
		var pCateName=src.substring(jj+10);		
	    $("#parentId").val(cateId);
	    $("#parentName").text(pCateName);
	    
	}
	
//表单验证
var validate = $("#fromProductCate").validate({		   
		rules:{					
			cateName:{
				  required:true,
			      remote: { 
	                   url: server_url+'/rest/productCate/checkCateName.do?timestamp='+Math.random()+ '&token=' + token,
	                   type: "post",
	                   dataType: "json", 
	                   data: {			                	     
	                	         cateName: function() { return $("#cateName").val();}
	                         } 
	               },
	               stringMaxLength:30
			},
		   sortNum:{
			   required:true,
			   stringMaxLength:30
		   }
		},
		messages:{				
			cateName:{
			      required:"该值不能为空！",
                  remote:"商品分类名已存在，请重新输入!",
                  stringMaxLength:"最多能输入30个字符！"
                 },
            sortNum:{
            	 required:"该值不能为空！",
            	 stringMaxLength:"最多能输入30个字符！"
             }
		},
		submitHandler:function(){
			sub();
		},
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo ( element.parent() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.parent() );
			else if ( element.is("input[name=captcha]") )
				error.appendTo ( element.parent() );
			else
				error.insertAfter(element);
		},
		validClass : 'rightValidate',
	    success: function(label) {
		   label.html("&nbsp;").text(" ") ;
	    }
 });
   

});

//提交
function sub(){	
		if($("#fromProductCate").valid()){
			$.ajax({
				url:server_url+'/rest/productCate/productCateAdd.do?ran='+Math.random()+ '&token=' + token,
				type:'post',
				data:$("#fromProductCate").serialize(),
				success:function(data){
					easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose : 2000});
					back();
				}
			});
		}	
}

function back(){
	
	var url="productCateList.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}

function submitCommit(){
	$("#fromProductCate").submit();
}
